<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" type="text/css" href="skin/base.css">
<link rel="stylesheet" type="text/css" href="skin/talk_form.css">
<link rel="stylesheet" type="text/css" href="skin/btn.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_json.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/login.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body>
<div id="main">
  <div class="textareadiv">
    <textarea id="msg" name="msg" placeholder="分享我的吃玩乐新鲜事～" ></textarea>
  </div>
  <div class="putimg" id="img_c">
    <div class="item" ontouchstart="zy_touch('down')" onclick="selectImg()" id="pic"></div>
	<div class="clear"></div>
  </div>

  <input name="img" value="" id="img" type="hidden">
  <div class="button pb" >
    <button class="shiny-blue"  ontouchstart="zy_touch('down')" onclick="gopost()" >动弹一下</button>
  </div>
</div>
</body>
<script>
	zy_init();	
	var Users= new Users({});
	var Div = '';
	function oklogin(msg){
		if (msg != 'maindata') {
			uexWindow.toast("0", "5", msg, 5000);
		}
	}
	
	function selectImg(){
		var image = getValue('img');
		uexWindow.cbActionSheet = function (opId, dataType, data){
			
			if (data == 0) { // 拍照
				uexCamera.open();
				uexCamera.cbOpen = cameraCallbcak;
			}
			else if (data == 1) { // 从手机相册选择
					uexImageBrowser.pick();
					uexImageBrowser.cbPick = function(opCode, dataType, data){
						if (dataType == 0) {
							setHtml('pic', '<img src="'+data+'" />');
							setValue('img', data);
						}
					}
				}else if (data == 2 && image) {	// 取消选择的照片
					delFileDir(image);
					setValue('img', '');
					setHtml('pic', '');
					
				}
			

		}
		if(image){
			uexWindow.actionSheet('','取消',['拍照', '从手机相册选择','取消选择的照片']);
		}else{
			uexWindow.actionSheet('','取消',['拍照', '从手机相册选择']);
		}
	}
	
	// 照相回调
	function cameraCallbcak(opId, dataType, data){
		if (dataType == 0) {
			setHtml(pic, '<img src="'+data+'" />');
			setValue('img', data);
		}
	}
	
	function Login(){
		Users.logout();
		localStorage['login']='tweet_pub';
		uexWindow.open('login', '0', 'login.html', 4, '', '', 0x0);
	}
	
	function gopost(){

		if (!Users.checkUser()) {
			Login();
			return false;
		}
		
		var msg = Trim($$('msg').value);

		if (msg == '') {
			uexWindow.alert('', '忘了说点什么～', '关闭');
			return false;
		}

		var img = getValue('img');
		
		var url = OpenAPI.tweet_pub+'/?client_id='+OpenAPI.client_id+'&access_token='+localStorage['access_token'];
		uexXmlHttpMgr.open(1,'post',url,"8000");
		if (img) uexXmlHttpMgr.setPostData(1,'1','img',img);	
		uexXmlHttpMgr.setPostData(1,'0','msg',msg);
		uexXmlHttpMgr.send(1);
		uexWindow.toast(1, 5, '提交中...', 0);
 
	}
	



	window.uexOnload=function(type){
		if (!type) {
			
			uexXmlHttpMgr.onData = function(opId, status, data){
				uexWindow.closeToast();
				if (status == 1) {
					data = JSON.parse(data);
					uexXmlHttpMgr.close(opId);
					if (data['error'] == '200') {
						uexWindow.evaluatePopoverScript('tweet','content','ok_tweet_pub()');
						uexWindow.evaluateScript('tweet_pub',0,'uexWindow.close(1)');
					}else {
						uexWindow.toast("0", "5", data['error_description'], 1000);
					}
				}else if (status == -1) {
					uexXmlHttpMgr.close(opId);
					uexWindow.toast("0", "5", '提交超时', 1000);
				}
			}
		}
	}
	</script>
</html>